package com.zyx.kafkademo.utils;

import com.zyx.kafkademo.common.CommonConfig;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

/**
 * @author zyx
 * @since 2021/5/29 08:48
 * desc: Kafka工具类
 */
public class KafkaUtils {
    public static  KafkaProducer<String, String> getKafkaProdocuer() {
        Properties prop = new Properties();
        prop.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, CommonConfig.COMPANY_KAFKA_SERVER);
        prop.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        prop.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        return new KafkaProducer<String, String>(prop);
    }
}
